package com.example.tedtalksimproved;

import java.util.ArrayList;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.example.tedtalksimproved.cache.MyVolley;
import com.example.tedtalksimproved.loader.VideoInfo;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<VideoInfo> videoinfo;
    ImageLoader imageloader;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {  
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
    	Log.d("ImageAdapter",
				"Made it here");
    	videoinfo = VideoListFragment.mAll;
    	imageloader = MyVolley.getImageLoader();
        NetworkImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new NetworkImageView(mContext);
            //imageView.setLayoutParams(new GridView.LayoutParams(240, 160));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        } else {
            imageView = (NetworkImageView) convertView;
        }
        VideoInfo item = videoinfo.get(position);
        if (item.getImage_url() != null) {
            imageView.setImageUrl(item.getImage_url(), imageloader);
        } else {
        	imageView.setImageResource(R.drawable.no_image);
        }
       // imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return VideoListFragment.mAll.size();
	}

}
